Dart double operator unary minus
Syntax & Examples
double.operator unary minus operator
The negate operator changes the sign of the given numeric value to its opposite and returns a double result.
Syntax of double.operator unary minus
The syntax of double.operator unary minus operator is:
operator unary-() → doubleThis operator unary minus operator of double negate operator.
✐ Examples
1 Example with positive value
In this example,
- We create a positive numeric value
numValuewith the value 10. - We then use the negate operator
-to change the sign ofnumValueto its opposite. - We print the negated result to standard output.
Dart Program
void main() {
num numValue = 10;
double result = -numValue;
print('Negate result: $result');
}Output
Negate result: -10.0
2 Example with floating-point value
In this example,
- We create a floating-point value
numValuewith the value 3.5. - We then use the negate operator
-to change the sign ofnumValueto its opposite. - We print the negated result to standard output.
Dart Program
void main() {
num numValue = 3.5;
double result = -numValue;
print('Negate result: $result');
}Output
Negate result: -3.5
3 Example with negative value
In this example,
- We create a negative numeric value
numValuewith the value -8. - We then use the negate operator
-to change the sign ofnumValueto its opposite. - We print the negated result to standard output.
Dart Program
void main() {
num numValue = -8;
double result = -numValue;
print('Negate result: $result');
}Output
Negate result: 8.0
Summary
In this Dart tutorial, we learned about operator unary minus operator of double: the syntax and few working examples with output and detailed explanation for each example.